#!/bin/bash
# packages settings

SCRIPT=$(readlink -f $0)
SCRIPT_DIR="$(dirname ${SCRIPT})"
SRC_ROOT=$(readlink -f ${SCRIPT_DIR}/..)

DEST_DIR="${SRC_ROOT}/docker/assets"
DEST_PYREQ_TMP="${DEST_DIR}/requirements.txt.tmp"
DEST_PYREQ="${DEST_DIR}/requirements.txt"

. ${SRC_ROOT}/config/common_scripts_lib
. ${SRC_ROOT}/config/bootstrap_config

printVar SCRIPT
printVar SCRIPT_DIR
printVar SRC_ROOT
printVar DEST_DIR

function get_arm_toolchain() {
    echo -e "\e[32m${FUNCNAME[0]}\e[0m"
    echo "Download gcc-arm"
    SUM_FILE="${ARM_GCC_PKG}.md5"
    wget --no-verbose --show-progress -c -O ${ARM_GCC_PKG} ${ARM_GCC_SOURCE_LINK}
    echo "${ARM_GCC_MD5} ${ARM_GCC_PKG}" > $SUM_FILE
    md5sum -c ${SUM_FILE}
}

function get_cmake() {
    echo -e "\e[32m${FUNCNAME[0]}\e[0m"
    wget --no-verbose --show-progress -c -O ${CMAKE_PKG} ${CMAKE_SOURCE_LINK}
    wget --no-verbose --show-progress -c ${CMAKE_SHA_LINK}
    cat ${CMAKE_SHA_FILE} | grep ${CMAKE_PKG} > ${CMAKE_SHA_FILE}
    sha256sum -c ${CMAKE_SHA_FILE}
}

function getPythonReq() {
    echo -e "\e[32m${FUNCNAME[0]}\e[0m"
    cat ${SRC_ROOT}/test/requirements.txt > ${DEST_PYREQ_TMP}
    cat ${SRC_ROOT}/config/requirements.txt >> ${DEST_PYREQ_TMP}
    cat ${DEST_PYREQ_TMP} | sort | uniq > ${DEST_PYREQ}
}

function get_CodeQL() {
    echo -e "\e[32m${FUNCNAME[0]}\e[0m"
    wget --no-verbose --show-progress -c -O ${CODEQL_PKG} ${CODEQL_SOURCE_LINK}
}

get_arm_toolchain
get_cmake
get_CodeQL
getPythonReq


